/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-4-30 下午4:22 Created by dwzhang
 */
package com.jade.bss.business.order;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;

/**
 * 客户订单。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-4-30 下午4:22
 */
@Entity
@Table (name = "BSS_ORDER")
public class Order
        implements Serializable
{
    //订单创建，待支付
    public static final int STATUS_CREATED = 0;
    //订单已支付，待发货
    public static final int STATUS_PAID = 1;
    //订单已发货，待接货
    public static final int STATUS_SENT = 3;
    //订单已收货，完成订单
    public static final int STATUS_FINISHED = 7;
    //订单已取消
    public static final int STATUS_CANCELLED = 9;
    @Id
    @GeneratedValue (generator = "SEQ_BSS_ORDER_ID")
    @SequenceGenerator (name = "SEQ_BSS_ORDER_ID", sequenceName = "SEQ_BSS_ORDER_ID")
    private long id;
    //订单类型
    @Column (name = "type", length = 32, nullable = false, updatable = false)
    private String type;
    //客户标识
    @Column (name = "customer_id", nullable = false, updatable = false)
    private long customerId;
    //商品数量
    @Column (name = "count", updatable = false)
    private int itemCount = 0;
    //商品总价
    @Column (name = "total_price", updatable = false)
    private double totalPrice;
    //实际交易价格
    @Column (name = "trade_price")
    private double tradePrice;
    //折扣,暂不用
    @Column (name = "discount")
    private int discount = 0;
    //状态
    @Column (name = "status", nullable = false)
    private int status = STATUS_CREATED;
    //备注
    @Column (name = "remark")
    private String remark;
    //创建日期
    @Column (name = "creation_date", nullable = false, updatable = false)
    private Date creationDate;
    //更新日期
    @Column (name = "update_date")
    private Date updateDate;
    @OneToMany (cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn (name = "order_id")
    private List<OrderItem> items;

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public long getCustomerId()
    {
        return customerId;
    }

    public void setCustomerId(long customerId)
    {
        this.customerId = customerId;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public double getTotalPrice()
    {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice)
    {
        this.totalPrice = totalPrice;
    }

    public double getTradePrice()
    {
        return tradePrice;
    }

    public void setTradePrice(double tradePrice)
    {
        this.tradePrice = tradePrice;
    }

    public int getItemCount()
    {
        return itemCount;
    }

    public void setItemCount(int itemCount)
    {
        this.itemCount = itemCount;
    }

    public int getDiscount()
    {
        return discount;
    }

    public void setDiscount(int discount)
    {
        this.discount = discount;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public String getRemark()
    {
        return remark;
    }

    public void setRemark(String remark)
    {
        this.remark = remark;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public Date getUpdateDate()
    {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate)
    {
        this.updateDate = updateDate;
    }

    public List<OrderItem> getItems()
    {
        return items;
    }

    public void setItems(List<OrderItem> items)
    {
        this.items = items;
    }

    public void addItem(OrderItem item)
    {
        if (items == null) {
            items = new ArrayList<OrderItem>();
        }
        items.add(item);
    }
}
